import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/Users/Login.vue'
import { useCounterStore } from '@/stores/counter'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    
    
    {
          
      path: '/Demo',
      name: 'Demo',
      component: () => import('../views/Demo.vue'),
    },
    {
      path: '/',
      name: 'Login',
      component: Login,
    },
    {
      //主页面
      path: '/HomeTotel',
      name: 'HomeTotel',
      component: () => import('../views/HomeTotel.vue'),
      children:[
        
        {
          path: '/HomeView',
          name: 'HomeView',
          component: () => import('../views/HomeView.vue'),
        },
        {
          path: '/about',
          name: 'about',
          // route level code-splitting
          // this generates a separate chunk (About.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import('../views/AboutView.vue'),
        },
        {
          //添加商品信息
          path: '/AddGoods',
          name: 'AddGoods',
          component: () => import('../views/Goods/AddGoods.vue'),
        },
        {
          //添加商品信息
          path: '/ShowGoods',
          name: 'ShowGoods',
          component: () => import('../views/Goods/ShowGoods.vue'),
        },
        {
          //修改商品信息
          path: '/EditGoods/:Gid',
          name: 'EditGoods',
          component: () => import('../views/Goods/EditGoods.vue'),
        },
        
        {
          //添加用户
          path: '/AddUser',
          name: 'AddUser',
          component: () => import('../views/Users/AddUser.vue'),
        },
        {
          //显示用户信息
          path: '/ShowUser',
          name: 'ShowUser',
          component: () => import('../views/Users/ShowUser.vue'),
        },
        {
          //添加角色权限
          path: '/AddPermission',
          name: 'AddPermission',
          component: () => import('../views/Users/AddPermission.vue'),
        },
        {
          //添加角色权限
          path: '/ShowRolePermission',
          name: 'ShowRolePermission',
          component: () => import('../views/Users/ShowRolePermission.vue'),
        },
        
        {
          //添加角色权限
          path: '/EditPermission/:Rid',
          name: 'EditPermission',
          component: () => import('../views/Users/EditPermission.vue'),
        },
        {
          //添加角色权限
          path: '/ShowOrder',
          name: 'ShowOrder',
          component: () => import('../views/Orders/ShowOrder.vue'),
        },
        
        {
          //添加角色权限
          path: '/Echarts',
          name: 'Echarts',
          component: () => import('../views/Orders/Echarts.vue'),
        },
      ]
    },
  ],
})

// //通过导航守卫进行数据判断
// router.beforeEach((to,from,next)=>{
//   //初见store实例
//   const stores=useCounterStore();
//   //如果未登录且跳转页面不是登录页面是,自动跳转到登录界面进行登录操作
//   if(to.name!=="Login"&&!stores.IsLogin){
//    // 跳转到登录页面
//     next("/Login")
//   }else next();
// })
export default router
